package mystia.lorelei.app.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import mystia.lorelei.app.entity.Activity;
import mystia.lorelei.app.service.ActivityService;
import mystia.lorelei.app.util.Result;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/activity")
@Tag(name = "活动管理")
public class ActivityController {
	@Resource
	private ActivityService activityService;

	@GetMapping("/list")
	@Operation(summary = "列出活动")
	public Result<List<Activity>> listActivity() {
		var activities = activityService.listActivity();
		return Result.ok(activities);
	}
	
	@PostMapping("/save")
	@Operation(summary = "保存活动")
	public Result saveActivity(@RequestBody Activity activity){
		try{
			activityService.saveActivity(activity);
			return Result.ok();
		}catch (Exception e){
			return Result.fail();
		}
	}

	@DeleteMapping("/delete/{id}")
	@Operation(summary = "根据id删除活动")
	public Result deleteActivity(@PathVariable("id") int id){
		try {
			activityService.deleteActivity(id);
			return Result.ok();
		} catch (Exception e){
			return Result.fail();
		}
	}
	@DeleteMapping("/delete")
	@Operation(summary = "批量删除活动")
	public Result deleteActivities(@RequestBody List<Integer> ids){
		try {
			activityService.deleteActivities(ids);
			return Result.ok();
		}catch (Exception e){
			return Result.fail();
		}
	}
}
